package com.hzp.lolnews.ui.news.view;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.hzp.lolnews.R;
import com.hzp.lolnews.base.BaseRecyclerViewHolder;
import com.hzp.lolnews.bean.HomeGrid;
import com.hzp.lolnews.ui.friends.fragment.FXFragment;

import java.util.List;

/**
 * Created by Administrator on 2016/10/20 0020.
 */
public class HomeGridAdapter extends RecyclerView.Adapter<BaseRecyclerViewHolder> {

    private List<HomeGrid> mList;

    private Context mContext;
    public void setData(List<HomeGrid> list, Context context) {
        this.mList = list;
        this.mContext = context;
        notifyDataSetChanged();
    }



    @Override
    public BaseRecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_head, parent, false);
        return new BaseRecyclerViewHolder(view);
    }

    @Override
    public void onBindViewHolder(BaseRecyclerViewHolder holder, int position) {
        HomeGrid homeGrid = mList.get(position);
        SimpleDraweeView simpleDraweeView = holder.getView(R.id.head_iv);
        simpleDraweeView.setImageURI(homeGrid.getImg());
        TextView tv = holder.getView(R.id.head_tv);
        tv.setText(homeGrid.getTitle());
        simpleDraweeView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mContext, FXFragment.class);
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList != null ? mList.size() : 0;
    }
}
